/*!
// Testweb v0.6.1
// http://or-change.cn
// Copyright 2014 OrChange Inc. All rights reserved.
// Licensed under the GPL License.
*/
/*jslint vars: true, forin: true */
/*global angular: false, $: false, probe: false */

probe.service("Engine", [function () {
	'use strict';

	var mapping = {
		ready: "等待打开或创建",
		edit: "正在编辑",
		play: "运行",
		stop: "停止",
		pause: "暂停"
	};
	var HEAD = null;
	var playerStatus = "stop";

	return {
		HEAD: function (process) {
			return angular.isDefined(process) ? (HEAD = process) : HEAD;
		},
		hasHEAD: function () {
			return HEAD !== null;
		},
		play: function () {
			if (playerStatus === "stop") {
				HEAD.play();
				playerStatus = "play";
			} else if (playerStatus === "pause") {
				HEAD.resume();
				playerStatus = "play";
			}
		},
		pause: function () {
			if (playerStatus === "play") {
				HEAD.pause();
				playerStatus = "pause";
			}
		},
		stop: function () {
			HEAD.stop();
			playerStatus = "stop";
		},
		step: function () {
			HEAD.debug();
		},
		status: function () {
			if (playerStatus === "play" || playerStatus === "pause") {
				return mapping[playerStatus] + "：" + HEAD.getLoop() + " / " + HEAD.loops();
			}

			if (this.hasHEAD()) {
				return mapping.edit;
			} else {
				return mapping.ready;
			}
		}
	};
}]);
